import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import demo1 from './demo1'
import demo2 from './demo2'

const routes: Array<RouteRecordRaw> = [
    {
        path: '/',
        name: '',
        component: () => import('views/PassPort/login.vue'),
    },
    // 登录
    {
        path: '/login',
        name: 'login',
        component: () => import('views/PassPort/login.vue'),
    },
    // 注册
    {
        path: '/register',
        name: 'register',
        component: () => import('views/PassPort/register.vue'),
    },
    // 忘记密码
    {
        path: '/forget',
        name: 'forget',
        component: () => import('views/PassPort/forget.vue'),
    },
    // 404
    {
        path: '/:catchAll(.*)', // 当所有路由找不到的时候会执行这个页面
        name: 'errorInfo',
        component: () => import('views/PassPort/error.vue'),
    },
    // 内容
    {
        path: '/home',
        name: 'home',
        // redirect: to => {
        //     return '';
        // },
        component: () => import('src/views/pages/index.vue'),
        children: [
            demo1,
            demo2,
        ],
    },
]

const router = createRouter({
    history: createWebHashHistory(),  // history 模式则使用 createWebHistory()
    routes,
})

// 路由跳转之前
/* router.beforeEach((to, from, next) => {
  const passportStore = usePassportStore() || {}; // 使用仓库
  if (
    to.path !== '/login' &&
    to.path !== '/' &&
    to.path !== '/register' &&
    to.path !== '/forget' &&
    // 如果不存在token，则不允许进行页面跳转
    !passportStore.utmToken
  ) {
    ElMessage.warning('请输入用户名和密码进行登录');
    return next('/login');
  }
  next();
}); */

export default router
